package com.show.dao.grid;


import com.show.dto.grid.Grid;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
 * Created by yxd on 2018/1/30.
 */
public interface GridRepositoty extends JpaRepository<Grid, String>, JpaSpecificationExecutor<Grid>, PagingAndSortingRepository<Grid, String> {

    @Query(value = "SELECT COUNT(*) FROM grid g WHERE g.grid_name = ? AND g.sts=1", nativeQuery = true)
    int findByGridName(String gridName);

    @Query(value = "SELECT COUNT(*) FROM grid g WHERE g.grid_code =? AND g.sts=1",nativeQuery = true)
    int findByGridCode(String gridCode);

    @Query(value = "SELECT COUNT(*) FROM cell_grid gc WHERE gc.cell_id =? ",nativeQuery = true)
    int findByCellId(String cellId);

    @Modifying
    @Query(value = "update grid set sts='0' where grid_id=?",nativeQuery = true)
    int update(String grid_id);
    @Modifying
    @Query(value = "DELETE FROM cell_grid  where grid_id=?",nativeQuery = true)
    void delete(String grid_id);

    @Query(value = "select * from  grid where grid_id=?",nativeQuery = true)
    Grid findOne(int grid_id);

}
